package com.example.dict;

import android.graphics.Bitmap;

public class Imaging {
	int w, h ;
	Bitmap bit = null;
	Imaging(Bitmap src) {
		bit = src;
		w = bit.getWidth();
		h = bit.getHeight();
	}
	public Bitmap getBitmap(){ return bit; }
	public void removeNoise() {
		int px, r, g, b;
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				px = bit.getPixel(x, y);
				r = (px >> 16) & 0xff;
				g = (px >> 8) & 0xff;
				b = px & 0xff;
				if(r+g+b<500) bit.setPixel(x, y, 0xffff0000);
				else bit.setPixel(x, y, 0xffffffff);
			}
		}
	}
	public void convertGraycode() {
		int px, r, g, b;
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				px = bit.getPixel(x, y);
				r = (px >> 16) & 0xff;
				g = (px >> 8) & 0xff;
				b = px & 0xff;
				if(r+g+b<500) bit.setPixel(x, y, 0xff000000);
				else bit.setPixel(x, y, 0xffffffff);
			}
		}
	}
}
